package com.xii.job;


import com.xii.constant.RedisConstant;
import com.xii.utils.QiniuUtils;
import redis.clients.jedis.JedisPool;

import java.util.Date;
import java.util.Set;

/**
 * @description: 清理垃圾图片
 *
 * @return {@link null}
 * @author  wangxihao
 * @email wangxh0108@163.com
**/
public class ClearImgJob {
    //注入jedis  直接使用getset  省的扫描注解
    private JedisPool jedisPool;

    //set 将bean注入
    public void setJedisPool(JedisPool jedisPool) {
        this.jedisPool = jedisPool;
    }

    public void clearImg(){
//        HashSet<String> rubbishimg = new HashSet<>();
//        rubbishimg.add("1.jpg");
//        rubbishimg.add("2.jpg");
//        rubbishimg.add("3.jpg");

        //得到垃圾图片
        Set<String> rubbishimg = jedisPool.getResource().sdiff(RedisConstant.SETMEALIMG_REDIS, RedisConstant.SETMEALIMG_DB_REDIS);
        for (String img : rubbishimg) {
            //七牛云删除图片
            QiniuUtils.deleteFileFromQiniu(img);
            //从redis中移除图片
            jedisPool.getResource().srem(RedisConstant.SETMEALIMG_REDIS,img);
            System.out.println(new Date()+" remove img name :  "+img);
        }
    }


}
